home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / samba / contributed / net.script < prev    next >
Encoding:
Korn shell script  |  1995-01-20  |  15.0 KB  |  554 lines

  1. #!/bin/ksh
  2. #
  3. # Please report changes and bugs to egan@cbs.cis.com
  4. # version .1
  5. # 10/24/94
  6. #
  7. # NOTES:
  8. # 1.  Use / where you would use \
  9. # 2.  Use - where you would use /
  10. #     e.g.  DOS:    NET TIME /SET \\CBS
  11. #           SAMBA:  net time -set //winnt
  12. # 3.  net logon/logoff is intended to be used with smbmount when it becomes
  13. #     available
  14. # 4.  net use (see 3.)
  15. # 5.  net password (dunno yet)
  16. # 6.  net init (?)
  17. # 7.  net view does not search other workgroups or list the machines in your
  18. #     workgroup.  Will when samba does.
  19. #
  20.  
  21.  
  22. PATH=/usr/samba/bin:$PATH
  23.  
  24. WORKGROUP=SLC
  25. COMMENT="AIX 3.2.5 Server"
  26. LOGFILE=/usr/samba/etc/smb.log
  27. DL=0
  28.  
  29. SAMBAVER=$(smbclient -h | head -2 | tail -1 | awk '{print $2}')
  30. SMBCONF=/usr/samba/etc/smb.conf
  31. ROOTDIR=$(grep "root dir" $SMBCONF | awk -F= '{print $2}' | awk '{print $1}')
  32. if [ -z "$ROOTDIR" ]
  33. then
  34.     ROOTDIR=/
  35. fi
  36. if [ -z "$PAGER" ]
  37. then
  38.     PAGER=more
  39. fi
  40.  
  41.  
  42. COMMAND=$1
  43. case $COMMAND in
  44.     config)
  45.         if [ "$2" = "-?" ]
  46.         then
  47.             echo
  48.             echo "Display your current Samba settings."
  49.             echo
  50.             echo "net config"
  51.             echo
  52.         else
  53.             echo "Computer name                  //$(uname -n)"
  54.             echo "User name                      $LOGNAME"
  55.             echo
  56.             echo "Software version               $(uname -s) $(uname -v).$(uname -r)"
  57.             echo "Samba version                  $SAMBAVER"
  58.             echo "Workstation root directory     $ROOTDIR"
  59.             echo
  60.             echo "Workgroup                      $WORKGROUP"
  61.         fi
  62.         ;;
  63.     diag)
  64.         if [ "$2" = "-?" ]
  65.         then
  66.             echo
  67.             echo "Display your Samba logfile."
  68.             echo
  69.             echo "net diag"
  70.             echo    
  71.         else
  72.             if [ -r $LOGFILE ]
  73.             then
  74.                 tail -f $LOGFILE
  75.             else
  76.                 echo "net diag: unable to read $LOGFILE"
  77.             fi
  78.         fi
  79.         ;;
  80.     logoff)
  81.         if [ "$2" = "-?" ]
  82.         then
  83.             echo
  84.             echo "Breaks the connections between your computer and the"
  85.             echo "shared resources to which it is connected."
  86.             echo
  87.             echo "net logoff [-y]"
  88.             echo
  89.             echo "  -y          Carries out the net logoff command without"
  90.             echo "              first prompting you to provide information or"
  91.             echo "              confirm actions."
  92.             echo
  93.         else
  94.             echo "Currently unavailable."
  95.         fi
  96.         ;;
  97.     logon)
  98.         if [ "$2" = "-?" ]
  99.         then
  100.             echo
  101.             echo "Identifies you as a member of a workgroup and"
  102.             echo "reestablishes your persistent connections."
  103.             echo
  104.             echo "net logon [-y]"
  105.             echo
  106.             echo "  -y          Carries out the net logon command without"
  107.             echo "              first prompting you to provide information or"
  108.             echo "              confirm actions."
  109.             echo
  110.         else
  111.             echo "Currently unavailable."
  112.         fi
  113.         ;;
  114.     password)
  115.         if [ "$2" = "-?" ]
  116.         then
  117.             echo
  118.             echo "Changes your logon password."
  119.             echo
  120.             echo "net password //computer | -domain:name [user [oldpassword [newpassword]]]"
  121.             echo
  122.             echo "  oldpassword   Specifies your current password."
  123.             echo "  newpassword   Specifies your new password.  It can have as"
  124.             echo "                many as 14 characters."
  125.             echo "  computer      Specifies the Windows NT or LAN Manager server"
  126.             echo "                on which you want to change your password."
  127.             echo "  -domain       Specifies that you want to change your"
  128.             echo "                password on a Windows NT or LAN Manager domain."
  129.             echo "  name          Specifies the Windows NT or LAN Manager domain on which"
  130.             echo "                you want to change your password."
  131.             echo "  user          Specifies your Windows NT or LAN Manager user name."
  132.             echo
  133.         else
  134.             echo "Currently unavailable."
  135.         fi
  136.         ;;
  137.     print)
  138.         if [ "$2" = "-?" ]
  139.         then
  140.             echo
  141.             echo "Displays information about the print queue on a shared or local"
  142.             echo "printer."
  143.             echo
  144.             echo "net print //computer[/printer]"
  145.             echo "net print [printer]"
  146.             echo
  147.             echo "  computer   Specifies the name of the computer whose"
  148.             echo "             print queue you want information about."
  149.             echo "  printer    Specifies the name of the printer you "
  150.             echo "             want information about."
  151.             echo
  152.             echo "When you specify the name of a computer by using the NET PRINT"
  153.             echo "command, you receive information about the print queues on"
  154.             echo "each of the shared printers that are connected to the computer."
  155.             echo
  156.         else
  157.             if [ -z "$2" ]
  158.             then
  159.                 lpstat
  160.             else
  161.                 lpstat -a$2
  162.             fi
  163.         fi
  164.         ;;
  165.     ps)
  166.         if [ "$2" = "-?" ]
  167.         then
  168.             echo
  169.             echo "Displays information about samba processes."
  170.             echo
  171.             echo "net ps"
  172.             echo
  173.         else
  174.             ps -ef | grep mbd | grep -v grep
  175.         fi
  176.         ;;
  177.     restart)
  178.         if [ "$2" = "-?" ]
  179.         then
  180.             echo
  181.             echo "Restarts services."
  182.             echo
  183.             echo "net restart [-y]"
  184.             echo
  185.             echo "  -y          Carries out the net stop command without"
  186.             echo "              first prompting you to provide information or"
  187.             echo "              confirm actions."
  188.             echo
  189.         else
  190.             if [ "$LOGNAME" = "root" ]
  191.             then
  192.                 if [ "$2" = "-y" ]
  193.                 then
  194.                     net stop -y
  195.                     net start -y
  196.                 else
  197.                     echo
  198.                     echo "Do you really want to restart samba services? \c"
  199.                     read YN
  200.                     case $YN in
  201.                         y|Y)
  202.                             net stop -y
  203.                             net start -y
  204.                             ;;
  205.                     esac
  206.                 fi
  207.             else
  208.                 echo
  209.                 echo "net restart: You must be logged in as root."
  210.                 echo
  211.             fi
  212.         fi
  213.         ;;
  214.     start)
  215.         if [ "$2" = "-?" ]
  216.         then
  217.             echo
  218.             echo "Starts services."
  219.             echo
  220.             echo "net start [-y]"
  221.             echo
  222.             echo "  -y          Carries out the net start command without"
  223.             echo "              first prompting you to provide information or"
  224.             echo "              confirm actions."
  225.             echo
  226.         else
  227.             if [ "$LOGNAME" = "root" ]
  228.             then
  229.                 if [ "$2" = "-y" ]
  230.                 then
  231.                     nmbd -D -d $DL -G $WORKGROUP -C "$COMMENT" -l $LOGFILE
  232.                 else
  233.                     echo
  234.                     echo "Do you really want to start samba services? \c"
  235.                     read YN
  236.                     case $YN in
  237.                         y|Y)
  238.                             nmbd -D -d $DL -G $WORKGROUP -C "$COMMENT" -l $LOGFILE
  239.                             ;;
  240.                     esac
  241.                 fi
  242.             else
  243.                 echo
  244.                 echo "net start: You must be logged in as root."
  245.                 echo
  246.             fi
  247.         fi
  248.         ;;
  249.     stop)
  250.         if [ "$2" = "-?" ]
  251.         then
  252.             echo
  253.             echo "Stops services."
  254.             echo
  255.             echo "net stop [-y]"
  256.             echo
  257.             echo "  -y          Carries out the net stop command without"
  258.             echo "              first prompting you to provide information or"
  259.             echo "              confirm actions."
  260.             echo
  261.         else
  262.             if [ "$LOGNAME" = "root" ]
  263.             then
  264.                 if [ "$2" = "-y" ]
  265.                 then
  266.                     for i in $((ps -e | \
  267.                         grep smbd; ps -e | \
  268.                         grep nmbd) | grep -v grep | \
  269.                         awk '{print $1}')
  270.                     do
  271.                         kill -1 $i >/dev/null 2>&1
  272.                         sleep 1
  273.                         kill -9 $i >/dev/null 2>&1
  274.                     done
  275.                 else
  276.                     echo
  277.                     echo "Do you really want to stop samba services? \c"
  278.                     read YN
  279.                     case $YN in
  280.                         y|Y)
  281.                             for i in $((ps -e | \
  282.                                 grep smbd; ps -e | \
  283.                                 grep nmbd) | grep -v grep | \
  284.                                 awk '{print $1}')
  285.                             do
  286.                                 kill -1 $i >/dev/null 2>&1
  287.                                 sleep 1
  288.                                 kill -9 $i >/dev/null 2>&1
  289.                             done
  290.                             ;;
  291.                     esac
  292.                 fi
  293.             else
  294.                 echo
  295.                 echo "net stop: You must be logged in as root."
  296.                 echo
  297.             fi
  298.         fi
  299.         ;;
  300.     time)
  301.         if [ "$2" = "-?" ]
  302.         then
  303.             echo
  304.             echo "Displays the time on or synchronizes your computer's "
  305.             echo "clock with the shared clock on a Microsoft Windows for "
  306.             echo "Workgroups, Windows NT, LAN Manager, or Samba time server."
  307.             echo
  308.             echo "net time //computer [-set]"
  309.             echo
  310.             echo "  computer    Specifies the name of the computer (time"
  311.             echo "              server) whose time you want to check or"
  312.             echo "              synchronize your computer's clock with."
  313.             echo "  -set        Synchronizes your computer's clock with the"
  314.             echo "              clock on the computer or workgroup you"
  315.             echo "              specify."
  316.             echo
  317.         else
  318.             HOST=$(echo $2 | tr -d '/')
  319.             if [ -z "$HOST" ]
  320.             then
  321.                 echo
  322.                 echo "net time: You must supply a host name."
  323.                 echo
  324.             else
  325.                 if [ "$3" = "-set" ]
  326.                 then
  327.                     if [ "$LOGNAME" = "root" ]
  328.                     then
  329.                         set $(smbclient -L $HOST | head -1)
  330.                         case $5 in
  331.                             Jan)
  332.                                 MM=01
  333.                                 ;;
  334.                             Feb)
  335.                                 MM=02
  336.                                 ;;
  337.                             Mar)
  338.                                 MM=03
  339.                                 ;;
  340.                             Apr)
  341.                                 MM=04
  342.                                 ;;
  343.                             May)
  344.                                 MM=05
  345.                                 ;;
  346.                             Jun)
  347.                                 MM=06
  348.                                 ;;
  349.                             Jul)
  350.                                 MM=07
  351.                                 ;;
  352.                             Aug)
  353.                                 MM=08
  354.                                 ;;
  355.                             Sep)
  356.                                 MM=09
  357.                                 ;;
  358.                             Oct)
  359.                                 MM=10
  360.                                 ;;
  361.                             Nov)
  362.                                 MM=11
  363.                                 ;;
  364.                             Dec)
  365.                                 MM=12
  366.                                 ;;
  367.                         esac
  368.                         DD=$6
  369.                         integer day=$6
  370.                         if ((day < 10))
  371.                         then
  372.                             DD="0$day"
  373.                         fi
  374.                         YY=$(echo $8 | awk '{print substr($1,3,2)}')
  375.                         set $(echo $7 | tr ':' ' ')
  376.                         date ${YY}${MM}${DD}${1}${2}.${3}
  377.                     else
  378.                         echo
  379.                         echo "net time //$HOST -set: You must be logged in as root."
  380.                         echo
  381.                     fi
  382.                 else
  383.                     smbclient -L $HOST | head -1 \
  384.                         | eval sed 's/Server\ time\ is/Current\ time\ at\ \\/\\/$HOST\ is/'
  385.                 fi
  386.             fi
  387.         fi
  388.         ;;
  389.     use)
  390.         if [ "$2" = "-?" ]
  391.         then
  392.             echo
  393.             echo "Connects or disconnects your computer from a shared"
  394.             echo "resource or displays information about your"
  395.             echo "connections."
  396.             echo
  397.             echo "net use /dir [//computer/directory [password | ?]]"
  398.             echo "    [-persistent:yes | no] [-savepw:no] [-y] [-n] "
  399.             echo
  400.             echo "net use /dir | //computer/directory -delete [-y] "
  401.             echo
  402.             echo "net use -persistent:yes | no | list | save | clear [-y] [-n]"
  403.             echo
  404.             echo "  dir         Specifies the unix directory you assign to a"
  405.             echo "              shared directory."
  406.             echo "  computer    Specifies the name of the computer sharing"
  407.             echo "              the resource."
  408.             echo "  directory   Specifies the name of the shared directory."
  409.             echo "  printer     Specifies the name of the shared printer."
  410.             echo "  password    Specifies the password for the shared "
  411.             echo "              resource, if any."
  412.             echo "  ?           Specifies that you want to be prompted for the "
  413.             echo "              password of the shared resource. You don't "
  414.             echo "              need to use this option unless the password is "
  415.             echo "              optional."
  416.             echo "  -persistent Specifies which connections should be"
  417.             echo "              restored the next time you log on to"
  418.             echo "              the network. It must be followed"
  419.             echo "              by one of the values below:"
  420.             echo "              yes   Specifies that the connection you are"
  421.             echo "                    making and any subsequent connections"
  422.             echo "                    should be persistent."
  423.             echo "              no    Specifies that the connection you are"
  424.             echo "                    making and any subsequent connections"
  425.             echo "                    should not be persistent."
  426.             echo "              list  Lists your persistent connections."
  427.             echo "              save  Specifies that all current"
  428.             echo "                    connections should be persistent."
  429.             echo "              clear Clears your persistent connections."
  430.             echo "  -savepw:no  Specifies that the password you type"
  431.             echo "              should not be saved in your password-list"
  432.             echo "              file. You need to retype the password the"
  433.             echo "              next time you connect to this resource."
  434.             echo "  -yes -y     Carries out the net use command without"
  435.             echo "              first prompting you to provide information or"
  436.             echo "              confirm actions."
  437.             echo "  -delete     Breaks the specified connection to a shared"
  438.             echo "              resource."
  439.             echo "  -no -n      Carries out the net use command, responding "
  440.             echo "              with NO automatically when you are prompted"
  441.             echo "              to confirm actions."
  442.             echo
  443.             echo "To list all of your connections, type net use without"
  444.             echo "options."
  445.             echo
  446.             echo "To see this information one screen at a time, type the"
  447.             echo "following at the command prompt:"
  448.             echo
  449.         else
  450.             echo "Currently unavailable."
  451.         fi
  452.         ;;
  453.     ver)
  454.         if [ "$2" = "-?" ]
  455.         then
  456.             echo
  457.             echo "Displays the type and version number of the MS LAN"
  458.             echo "redirector you are using."
  459.             echo
  460.             echo "  net ver"
  461.             echo
  462.         else
  463.             echo "Samba $SAMBAVER"
  464.         fi
  465.         ;;
  466.     view)
  467.         if [ "$2" = "-?" ]
  468.         then
  469.             echo
  470.             echo "Displays a list of computers in a specified workgroup or"
  471.             echo "the shared resources available on a specified computer."
  472.             echo
  473.             echo "  net view [//computer]"
  474.             echo "  net view [-workgroup:wgname] (unsupported)"
  475.             echo "  net view [-IP:computer]"
  476.             echo
  477.             echo "  computer    Specifies the name of the computer whose"
  478.             echo "              shared resources you want to see listed."
  479.             echo "  -workgroup  Specifies that you want to view the names "
  480.             echo "              of the computers in another workgroup that"
  481.             echo "              share resources. "
  482.             echo "  wgname      Specifies the name of the workgroup whose"
  483.             echo "              computer names you want to view."
  484.             echo "  -IP         Specifies IP address of remote computer."
  485.             echo
  486.             echo "To display a list of computers in your workgroup that share"
  487.             echo "resources, type NET VIEW without options."
  488.             echo
  489.         else
  490.             HOST=$(echo $2 | tr -d '/')
  491.             if [ -z "$HOST" ]
  492.             then
  493.                 echo
  494.                 echo "net view: You must supply a host name."
  495.                 echo
  496.             else
  497.                 FC=$(echo $HOST | awk '{print substr($1,1,1)}')
  498.                 if [ "$FC" = "-" ]
  499.                 then
  500.                     echo $HOST | if grep : >/dev/null 2>&1
  501.                     then
  502.                         IP=$(echo $HOST | \
  503.                             awk -F: '{print substr($1,2,length($1)-1)}')
  504.                         COMP=$(echo $HOST | awk -F: '{print $2}')
  505.                         echo "Shared resources at -$IP:$COMP"
  506.                         smbclient -L $COMP -I $IP | tail +3 | sed 's/^ //'
  507.                     else
  508.                         echo
  509.                         echo "net view:  Must be in -IP:computer format."
  510.                         echo
  511.                     fi
  512.                 else
  513.                     echo "Shared resources at //$HOST"
  514.                     smbclient -L $HOST | tail +3 | sed 's/^    //'
  515.                 fi
  516.             fi
  517.         fi
  518.         ;;
  519.     *)
  520.         echo
  521.         echo "For more information about a specific net"
  522.         echo "command, type the command name followed by -?"
  523.         echo "(for example, net view -?)."
  524.         echo
  525.         echo "net          Same as 'net help'"
  526.         echo "net config   Displays information about your Samba settings."
  527.         echo "net diag     tail -f LOGFILE"
  528.         echo "net help     Provides information about commands."
  529.         echo "net logoff   Breaks the connection between your computer and"
  530.         echo "             the shared resources to which it is connected."
  531.         echo "net logon    Identifies you as a member of a workgroup and"
  532.         echo "             reestablishes your persistent connections."
  533.         echo "net password Changes your logon password."
  534.         echo "net print    Displays information about print queues."
  535.         echo "net ps       Displays information about samba processes."
  536.         echo "net restart  Restarts services."
  537.         echo "net start    Starts services."
  538.         echo "net stop     Stops services."
  539.         echo "net time     Displays the time on or synchronizes your"
  540.         echo "             computer's clock with the clock on a Microsoft"
  541.         echo "             Windows for Workgroups, Windows NT, LAN Manager,"
  542.         echo "             or Samba time server."
  543.         echo "net use      Connects to or disconnects from a shared"
  544.         echo "             resource or displays information about"
  545.         echo "             connections."
  546.         echo "net ver      Displays the type and version number of the"
  547.         echo "             MS LAN redirector you are using."
  548.         echo "net view     Displays a list of computers that share"
  549.         echo "             resources or a list of shared resources"
  550.         echo "             on a specific computer."
  551.         ;;
  552. esac
  553.  
  554.